package com.wz.boot.function.boast;

import com.wz.boot.annotation.Function;
import com.wz.boot.annotation.Handle;
import com.wz.boot.utils.HttpUtils;
import love.forte.common.ioc.annotation.Beans;
import love.forte.simbot.api.message.events.PrivateMsg;
import love.forte.simbot.api.sender.Sender;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

@Function(
        priority = 6,
        name = "沙雕语录",
        describe = "看我怎么夸你~",
        touch = "沙雕语录",
        claName = "Boast",
        level = 2
)
@Beans
@Component
public class Boast {
    private static Logger logger = LoggerFactory.getLogger(Boast.class);

    @Handle
    public void say(PrivateMsg privateMsg, Sender sender){
        sender.sendPrivateMsg(privateMsg,getChp());
    }


    private static List<String> list = new ArrayList<>();
    public static String getChp() {
        String url = "https://chp.shadiao.app/api.php";
        logger.info("沙雕语录缓冲池大小:{}", list.size());
        if(list.size() > 50){
            return list.get(new Random().nextInt(100));
        }
        String str = HttpUtils.get(url).getResponse();//HttpRequest.get(url) .execute() .asString();
        list.add(str);

        return str;
    }
}
